//
//  SLWBMainController.swift
//  SinaWeiBo
//
//  Created by 孙磊 on 15/9/29.
//  Copyright © 2015年 Sun. All rights reserved.
//

import UIKit

class SLWBMainController: UITabBarController {

    @IBOutlet weak var mainTabBar: SLWBMainTabBar!
    override func viewDidLoad() {
        super.viewDidLoad()
        //添加子视图控制器
        addChildViewControllers()
        //添加按钮的点击方法
        mainTabBar.midButton.addTarget(self, action: "didClickMidButton", forControlEvents: UIControlEvents.TouchUpInside)
        //试验下git
    }
    
    //中间按钮的点击方法
    func didClickMidButton(){
        print("didClickMidButton")
    }
    
    //添加子视图控制器
    func addChildViewControllers(){
        //简便设置tabBar图标颜色
        tabBar.tintColor = UIColor.orangeColor()
        addChildViewController("Home", title: "首页", imageName: "tabbar_home")
        addChildViewController("Message", title: "信息", imageName: "tabbar_message_center")
        addChildViewController("Discover", title: "发现", imageName: "tabbar_discover")
        addChildViewController("Profile", title: "我的", imageName: "tabbar_profile")
    }
    //详细设置各个子视图控制器
    func addChildViewController(sbName:String,title:String,imageName:String){
        //获取storyboard
        let sb = UIStoryboard.init(name: sbName, bundle: nil)
        //从storyboard获取初始加载的控制器
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        //修改nav跟控制器的title
        nav.topViewController?.title = title
        //设置nav在tabBar中的图片
        nav.tabBarItem.image = UIImage(named: imageName)
        //将nav作为子控制器添加到tabBar上
        addChildViewController(nav)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
